/**
 * 
 */
package hu.gbalage.owlforms.internal.rules;

import java.util.Set;

import org.semanticweb.owl.inference.OWLReasonerException;
import org.semanticweb.owl.model.OWLClass;
import org.semanticweb.owl.model.OWLIndividual;

import hu.gbalage.owlforms.OWLFormsManager;

/**
 * @author balage
 *
 */
public class RuleApplier {

	IRule[] rules;
	
	OWLFormsManager manager;
	
	public RuleApplier(OWLFormsManager manager){
		this.manager = manager;
		rules = new IRule[]{
			new EgyForeEsoJovedelemRule(manager)	
		};
	}
	
	public void apply(OWLIndividual individual) throws OWLReasonerException{
		for(IRule rule : rules){
			OWLClass on = manager.getDataFactory().getOWLClass(rule.runsOn());
			boolean canrun = false;
			for(Set<OWLClass> clazzes :manager.getReasoner().getTypes(individual, true)){
				for(OWLClass clazz : clazzes)
					if (manager.getReasoner().isSubClassOf(clazz, on)) canrun = true;
			}
			if (canrun) rule.execute(individual);
		}
	}
	
}
